﻿using System.Collections.Generic;
using System.Linq;
using Microsoft.SharePoint.Administration;

namespace Trentacular.SharePoint.Deployment.Model
{
    public class WebApplication : BaseFeatureContainer<WebApplicationFeature, WebApplication>
    {
        public virtual Farm Farm { get; set; }

        public virtual string Url { get; set; }

        public virtual IList<Site> Sites { get; set; }

        public virtual IList<FeatureDefinition> AvailableFeatureDefinitions { get; set; }

        public override IList<WebApplicationFeature> Features { get; set; }

        public virtual IEnumerable<Solution> DeployedSolutions
        {
            get
            {
                return Farm.Solutions.Where(s => s.Deployed &&
                        (
                            s.DeploymentState == SPSolutionDeploymentState.GlobalDeployed ||
                            s.DeployedWebApplications.Contains(this)
                        )
                    );
            }
        }
    }
}
